# encoding: UTF-8
'''
Created on 2013年11月6日

@author: xuben

集市
'''

from ..common import Command, Logger, RequestModel
from ..common.SocketService import gameSocketService
import ResourceData

class MarketGetInfoRequest(RequestModel.RequestModel):
    '''
    classdocs
    '''
    
    def setCommand(self):
        self.command = Command.GET_MARKET_INFO
        
    def onReceive(self, data):
        ResourceData.updateMarket(data)

'''
集市购买
'''
def marketBuyGoods(goodsId):
    command = Command.MARKET_BUY
    params = 'id=' + str(goodsId)
    gameSocketService.send(command, params, marketBuyGoodsCallback)
    
'''
集市购买回调函数
'''
def marketBuyGoodsCallback(data):
    if 'type' in data and 'addNum' in data:
        Logger.log('集市购买商品, type:' + str(data['type']) + ', num:' + str(data['addNum']), output = True)